package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.GenerateRFCPanel;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs.listeners.CancelRFCButtonListener;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs.listeners.CommitButtonListener;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs.listeners.DeleteRFCButtonListener;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs.listeners.EditButtonListener;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs.listeners.GenerateNewRFCButtonListener;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.generateRFCPanel.generateRFCSubs.listeners.SaveRFCButtonListener;

public class GenRFCFunctionPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JButton bu_save;
	private JButton bu_cancel;
	private JButton bu_newRFC;
	private JButton bu_sendRFC;
	private JButton bu_deleteRFC;
	private JButton bu_editButton;
	private JLabel lb_progressbar;

	private GenerateNewRFCButtonListener generateNewRFCButtonListener;
	private CancelRFCButtonListener cancelRFCButtonListener;
	private SaveRFCButtonListener saveRFCButtonListener;
	private CommitButtonListener commitButtonListener;
	private EditButtonListener editButtonListener;
	private DeleteRFCButtonListener deleteRFCButtonListener;
	
	private ArrayList<JButton> buttons;
	
	public GenRFCFunctionPanel(GenerateRFCPanel generateRFCPanel) {

		this.setPreferredSize(new Dimension(250, 600));
		this.bu_cancel = new JButton("Abbrechen");
		this.bu_newRFC = new JButton("Neues RFC erstellen");
		this.bu_save = new JButton("RFC Speichern");
		this.bu_sendRFC = new JButton("RFC absenden");
		this.bu_editButton = new JButton("RFC bearbeiten");
		this.bu_deleteRFC = new JButton("RFC verwerfen");
		
		this.buttons = new ArrayList<JButton>();
		this.buttons.add(bu_cancel);
		this.buttons.add(bu_deleteRFC);
		this.buttons.add(bu_editButton);
		this.buttons.add(bu_newRFC);
		this.buttons.add(bu_save);
		this.buttons.add(bu_sendRFC);

		this.lb_progressbar = new JLabel(new ImageIcon(
				"Pictures\\progressbar_cont.gif"));
		this.lb_progressbar.setVisible(false);

		this.bu_cancel.setEnabled(false);
		this.bu_save.setEnabled(false);
		this.bu_deleteRFC.setEnabled(false);
		this.bu_sendRFC.setEnabled(false);

		this.generateNewRFCButtonListener = new GenerateNewRFCButtonListener(
				this, generateRFCPanel);
		this.bu_newRFC.addActionListener(generateNewRFCButtonListener);

		this.cancelRFCButtonListener = new CancelRFCButtonListener(this, generateRFCPanel);
		this.bu_cancel.addActionListener(cancelRFCButtonListener);
		
		this.deleteRFCButtonListener = new DeleteRFCButtonListener(generateRFCPanel);
		this.bu_deleteRFC.addActionListener(deleteRFCButtonListener);
		
		this.saveRFCButtonListener = new SaveRFCButtonListener(generateRFCPanel, lb_progressbar);
		this.bu_save.addActionListener(saveRFCButtonListener);
		
		this.commitButtonListener = new CommitButtonListener(generateRFCPanel, this);
		this.bu_sendRFC.addActionListener(commitButtonListener);
		
		this.editButtonListener = new EditButtonListener(generateRFCPanel);
		this.bu_editButton.addActionListener(editButtonListener);
		
		this.add(new Buttonlist(), BorderLayout.NORTH);

	}

	private class Buttonlist extends JPanel {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private Buttonlist() {

			setLayout(new GridLayout(7, 1));

			add(bu_newRFC);
			add(bu_editButton);
			add(bu_save);
			add(bu_deleteRFC);
			add(bu_cancel);
			add(bu_sendRFC);
			add(lb_progressbar);
		}
	}
	
	public void changeButtonstate(){
		for (JButton button : this.buttons) {
			if (button.isEnabled()) {
				button.setEnabled(false);
			}else if (!button.isEnabled()) {
				button.setEnabled(true);
			}
		}
	}

	public JButton getBu_save() {
		return bu_save;
	}

	public JButton getBu_cancel() {
		return bu_cancel;
	}

	public JButton getBu_newRFC() {
		return bu_newRFC;
	}

	public JButton getBu_sendRFC() {
		return bu_sendRFC;
	}

	public JLabel getLb_progressbar() {
		return lb_progressbar;
	}

	public JButton getBu_editButton() {
		return bu_editButton;
	}

	public JButton getBu_deleteRFC() {
		return bu_deleteRFC;
	}

}
